package autokeyboard.handler;

import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;


/**
 * This class is used to call all event from AutoKeyboard window
 * @author HoldTheHand
 */
public class AutoKeyboardEvent 
{
	public JFrame frame;
	public ShowDialogEvent showDlg = new ShowDialogEvent();
	
	public AutoKeyboardEvent(JFrame frame)
	{
		this.frame = frame;
	}
	
	/**
	 * This method will set your frame look and feel with your input look and feel name
	 * @param name
	 */
	public void setLookAndFeel(String name)
	{
		try
		{
			for(UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
			{
				if(name.equals(info.getName()))
				{
					UIManager.setLookAndFeel(info.getClassName());
					SwingUtilities.updateComponentTreeUI(frame);
					break;
				}
			}
		}catch(Exception e){}
	}
	
	/**
	 * This method will show help topic dialog
	 */
	public void menuItemHelpTopicEvent()
	{
		showDlg.showHelpDialog(frame);
	}

	/**
	 * This method will show about dialog
	 */
	public void menuItemAboutEvent()
	{
		showDlg.showAboutWindow(frame);
	}
	
	/**
	 * This method will show open dialog
	 */
	public void menuItemOpenEvent(JTable table, ArrayList<Object[]> listObject)
	{
		showDlg.setTableAndList(table, listObject);
		showDlg.showOpenDialog(frame);
	}
	
	/**
	 * This method will show save as dialog if it's new file
	 * <p>
	 * if your file is exit it will override to your exist file
	 */
	public void menuItemSaveEvent(JTable table, ArrayList<Object[]> listObject)
	{
		showDlg.setTableAndList(table, listObject);
		showDlg.showSaveDialog(frame);
	}
	
	/**
	 * this method will show save as dialog
	 */
	public void menuItemSaveAsEvent(JTable table, ArrayList<Object[]> listObject)
	{
		showDlg.setTableAndList(table, listObject);
		showDlg.showSaveAsDialog(frame);
	}
	
	/**
	 * This method will clear all item from main table. And ask you to save your current file if it's edited
	 */
	public void menuItemNewEvent(JTable table, ArrayList<Object[]> listObject)
	{
		showDlg.setTableAndList(table, listObject);
		showDlg.newFileEvent(frame);
	}
	
	/**
	 * This method will ask you to save before exit if your table is changed. Unless your table is changed it will exit normally
	 */
	public void menuItemExitEvent()
	{
		showDlg.exitAsking(frame);
	}
}
